#
# Ref:
#   https://www.toutiao.com/i7017312732085060110/
#

import numpy as np
import matplotlib.pyplot as plt
import random

v=3*(10**8)*(10**6)*(10**(-15)) 
L=0.589
w=2*np.pi*v/L

def func_A(t,q,x,y,x0,y0):
    r = ((x - x0) ** 2 + (y - y0) ** 2) ** 0.5
    A=np.cos(w*(t-r/v)+q)
    return A



def f(t,x, y):
    A1 = func_A(t, 0,x, y, 0, 2)
    A2 = func_A(t,0, x, y, 0, -2)
    return ((A1+A2)**2)

x = np.linspace(0, 8, 1000)
y = np.linspace(-5, 5, 1000).reshape(-1, 1)

# single plot
fig, ax = plt.subplots()
ax.set_xticks([])
ax.set_yticks([])

ax.imshow(f(0,x, y))
plt.show()


# animation 
for i in range(10):
    fig, ax = plt.subplots()
    ax.set_xticks([])
    ax.set_yticks([])

    ax.imshow(f(i*0.3,x, y))
    plt.show()

# merge effect
z=f(0,x, y)
for i in range(1,10):
    z=f(i*0.3,x, y)+z
    
fig, ax = plt.subplots()
ax.set_xticks([])
ax.set_yticks([])

ax.imshow(z)
plt.show()

